package com.qf.forumproject.course.controller;

import com.qf.forumproject.utils.CourseVo;
import com.qf.forumproject.utils.Result;
import com.qf.forumproject.utils.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.qf.forumproject.course.service.QfCourseContentService;
import org.springframework.web.bind.annotation.*;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * (QfCourseContent)控制层
 *
 * @author protagonist
 * @since 2022-07-23 11:43:01
 */
@RestController
@Slf4j
@RequestMapping("/qfCourseContent")
@Api(tags = "课程内容专栏接口")
public class QfCourseContentController {
    /**
     * 服务对象
     */
    @Resource
    private QfCourseContentService qfCourseContentServiceImpl;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping(value = "/get/{id}")
    public Result selectById(@PathVariable("id") Integer id) {
        List<CourseVo> courseVos = qfCourseContentServiceImpl.selectById(id);
        if(Objects.nonNull(courseVos)){
            return new Result<>(true, StatusCode.OK,"查询成功",courseVos);
        }
        return new Result<>(true,StatusCode.ERROR,"查询失败");
    }

    /**
     * 查询全部
     *
     * @return Result对象
     */
    @GetMapping(value = "/selectAll")
    @ApiOperation(value = "查询所有课程")
    public Result<List<CourseVo>> selectAll() {
        List<CourseVo> qfCourseContents = qfCourseContentServiceImpl.selectAll();
        if (CollectionUtils.isEmpty(qfCourseContents)) {
            return new Result<>(true,StatusCode.ERROR,"查询全部数据失败");       
        }
        return new Result<>(true,StatusCode.OK,"查询全部数据成功",qfCourseContents);
        
    }

//    @GetMapping(value = "/updatePeople/{id}")
//    @ApiOperation("更新观看人数")
//    public Result updateCount(@PathVariable("id") Integer id){
//
//        QfCourseContent content = qfCourseContentServiceImpl.updateCount(id);
//
//        if (content != null) {
//            return new Result<>(true,StatusCode.OK,"观看人数跟新成功",content);
//        }
//        return new Result<>(true,StatusCode.ERROR,"观看人数跟新失败");
//    }

    @GetMapping(value = "/selectAllzhuanlan")
    @ApiOperation(value = "查询所有课程")
    public Result<List<CourseVo>> selectAllzhuanlan() {
        List<CourseVo> qfCourseContents = qfCourseContentServiceImpl.selectAllzhuanlan();
        if (CollectionUtils.isEmpty(qfCourseContents)) {
            return new Result<>(true,StatusCode.ERROR,"查询全部数据失败");
        }
        return new Result<>(true,StatusCode.OK,"查询全部数据成功",qfCourseContents);

    }
}
